/**
 * Created by Administrator on 2017/2/21.
 */
(function (app) {
    app.controller("projectsController", projects);
    function projects($scope, $rootScope) {

        $rootScope.title = 'Projects';

        mui('body').on('tap', '.mui-table-view-cell', function (e) {
            mui.openWindow({
                url:'#/main/projectDetails',
                id:'projectDetails.html',
            })
        });
        loadPullRefresh();

        function loadPullRefresh() {

            mui.plusReady(function () {
                mui('.mui-scroll-wrapper').scroll({
                    deceleration: 0.0005, //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
                    indicators: false
                });
            });


//-----------Mui初始化-------------

            mui.init({
                swipeBack: false,
                pullRefresh: {
                    container: '#pullrefresh',
                    down: {
                        callback: pulldownRefresh,
                        height: 50,
                        auto: false,
                        contentdown: "下拉可以刷新", //可选，在下拉可刷新状态时，下拉刷新控件上显示的标题内容
                        contentover: "释放立即刷新", //可选，在释放可刷新状态时，下拉刷新控件上显示的标题内容
                        contentrefresh: "正在刷新", //可选，正在刷新状态时，下拉刷新控件上显示的标题内容
                        contentmore: '刷新完成'
                    },
                    up: {
                        height: 50,//可选.默认50.触发上拉加载拖动距离
                        auto: true,//可选,默认false.自动上拉加载一次
                        contentrefresh: "正在加载...",//可选，正在加载状态时，上拉加载控件上显示的标题内容
                        contentnomore: '没有更多数据了',//可选，请求完毕若没有更多数据时显示的提醒内容；
                        callback: pullupRefresh //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
                    }
                }

            });

//-----------下拉刷新-------------


            function pulldownRefresh() {
                var text = document.getElementsByClassName("mui-pull-caption");
                setTimeout(function () {
                    text[0].innerHTML = "刷新完成";
                }, 1500);
                setTimeout(function () {
                    location.reload()
                    mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); //refresh completed

                }, 2000);
            }

//-----------上拉加载-------------

            var count = 0;

            function pullupRefresh() {

                setTimeout(function () {
                    mui('#pullrefresh').pullRefresh().endPullupToRefresh((++count > 2)); //参数为true代表没有更多数据了。

                    var table = document.body.querySelector('.mui-table-view');
                    var cells = document.body.querySelectorAll('.mui-table-view-cell');

                    for (var i = cells.length + 1, len = i + 20; i < len; i++) {
                        var li = document.createElement('li');
                        li.className = 'wow bounceInLeft  animated mui-table-view-cell mui-media';
                        li.innerHTML = '<img class="mui-media-object mui-pull-left shake shake-slow" src="assets/images/project5.png">'
                            + '<div class="mui-media-body" ng-click="toDetails()">'
                            + '项目'
                            + i
                            + ' <p class="mui-ellipsis">能和心爱的人一起睡觉，是件幸福的事情；可是，打呼噜怎么办？</p>'
                            + '</div>';
                        table.appendChild(li);
                    }

                }, 1000);
            }
        }

    }


})(angular.module(APP_NAME));


